<template>
  <a-input-number
    v-bind="$attrs"
    v-on="$attrs"
    :precision="precision"
    :disabled="disabled"
    :min="min"
    :max="_max"
    hide-button
    :placeholder="placeholder"
    :allow-clear="allowClear"
  >
    <template #append v-if="unit || $slots.append">
      <slot name="append">
        {{ unit }}
      </slot>
    </template>
  </a-input-number>
</template>

<script setup name="i-input-number">
  import { computed } from 'vue'
  const props = defineProps({
    precision: {
      type: Number,
      default: 2,
    },
    min: {
      type: Number,
      default: 0,
    },
    max: Number,
    disabled: {
      type: Boolean,
      default: false,
    },
    allowClear: {
      type: Boolean,
      default: true,
    },
    placeholder: {
      type: String,
      default: '请输入',
    },
    unit: {
      type: String,
      default: '元',
    },
  })

  const _max = computed(() => {
    let precision = props.precision
    if (props.max || props.max === 0) return props.max
    // 整数
    if (precision == 0) {
      return 99999999
    } else {
      return 99999999.99
    }
  })
</script>
